package com.gel.shortLink.common.biz;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;

import java.io.IOException;
import java.util.List;

@RequiredArgsConstructor
public class UserTransmitFilter implements Filter {





    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String username = request.getHeader("username");
        if(StrUtil.isNotBlank( username)){
            String userId=request.getHeader("userId");
            String realName=request.getHeader("realName");
            UserInfoDTO userInfoDTO = new UserInfoDTO(userId, username, realName);
            UserContext.setUser(userInfoDTO);
        }
        try{
            filterChain.doFilter(servletRequest,servletResponse);
        }finally {
            UserContext.clear();
        }
    }
}
